package com.shop.util;



import java.util.UUID;


/**
 * @author : WanS
 * @date : 15:48 2020/11/27
 *生成唯一图片名称
 * @Param: fileName
 * * @return: 云服务器fileName
 */
public class StringUtil {


    public static String getRandomImgName(String fileName) {

        int index = fileName.lastIndexOf(".");

        if ((fileName == null || fileName.isEmpty()) || index == -1){
            throw new IllegalArgumentException();
        }
        // 获取文件后缀
        String suffix = fileName.substring(index);
        // 生成UUID
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        // 生成上传至云服务器的路径
        String path = "code/duck/"+ "-" + uuid + suffix;
        return path;
    }
}
